import React from 'react';
import {Link} from 'react-router';
import moment from 'moment';
import Table, {
    setColumnKeys
} from '../_/table';
import redux from '../_/redux';
@redux("visitView", {
    actions: ['load'],
    loadArgs: [{visitDate: moment().format('YYYY-MM-DD')}]
})
export default class myPatientTable extends React.Component {
    componentWillReceiveProps(props) {
        if (props.refresh !== this.props.refresh || props.query !== this.props.query) {
            if (props.query !== this.props.query || typeof props.query !== "undefined") {
                if (typeof props.query.visitDate === "object" && props.query.visitDate !== null) {
                    props.query.visitDate = props.query.visitDate.format("YYYY-MM-DD");
                }
                this.props.load(props.query);
            } else {
                this.props.load({visitDate: moment().format('YYYY-MM-DD')});
            }
        }
    }
    onRowClick(record) {
        this.props.onRowClick('open', record);
    }

    render() {
        const {data = []} = this.props;
        const dataSource = data;
        const columns = [/*{
            title: '条码号',
            dataIndex: 'PATIENT_BAR_CODE',
        }, */{
            title: '患者Id',
            dataIndex: 'patientId',
        }, {
            title: '姓名',
            dataIndex: 'Name',
        }, {
            title: '年龄',
            dataIndex: 'Birthday',
            render: (val) => (typeof val !== "string" ? val.format('YYYY-MM-DD') : val)
        }, {
            title: '挂号日期',
            dataIndex: 'createDate',
            render: (val) => (typeof val !== "string" ? val.format('YYYY-MM-DD') : moment(val).format("YYYY-MM-DD"))
        }, {
            title: '医师',
            dataIndex: 'doctor',
        }, {
            title: '号别',
            dataIndex: 'chargeType',
        }, {
            title: '操作',
            render: (val, data) => (
                <span>
                    <a className="blue" onClick={() => this.props.showPE("showMyPatientEdit", data)}>
                        编 辑
                    </a>
                    <span className="ant-divider"/>
                    <Link className="blue" to={`/writeReport/${data.Id}`}>
                        接 诊
                    </Link>
                </span>
            )
        }];
        setColumnKeys(columns);
        return (<div className="w100 padding-t">
            <Table
                columns={columns}
                dataSource={dataSource}
                {...this.props}
                onRowClick={this.onRowClick.bind(this)}
            />
        </div>);
    }
}
